package com.mkb.enums;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * @author meikb
 * @desc
 * @date 2024-03-20 15:36
 */
@Getter
public enum  GraphEnum {
    POLYGON("Polygon", 0),
    CIRCLE("Point", 1),
    TEXT("Text", 2),
            ;

    /**
     * 描述
     */
    private String desc;

    /**
     * 枚举值
     */
    private int value;

    public static Map<Integer, String> getMap() {
        Map<Integer, String> map = new HashMap<>();

        GraphEnum[] values = GraphEnum.values();
        for (GraphEnum obj : values) {
            map.put(obj.getValue(), obj.getDesc());
        }

        return map;
    }

    GraphEnum(String desc, int value) {
        this.desc = desc;
        this.value = value;
    }

    public static GraphEnum getEnum(int value) {
        GraphEnum resultEnum = null;
        GraphEnum[] enumAry = GraphEnum.values();

        for (int i = 0; i < enumAry.length; i++) {
            if (enumAry[i].getValue() == value) {
                resultEnum = enumAry[i];
                break;
            }
        }

        return resultEnum;
    }
}
